package com.kube.design.proxy.interfaceproxy;

import java.lang.reflect.Proxy;

/**
 * @author q.zhangr
 * @version 1.0.0
 * @date 2020/7/20
 */
public class ProxyFactory {


    /**
     * 维护一个目标对象
     */
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {

        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
                (proxy, method, args) -> {

                    System.out.println("开始事务2");
                    Object invoke = method.invoke(target, args);
                    System.out.println("提交事务2");
                    return invoke;
                });
    }

}
